package com.mate.cloud.lettuce;

import io.lettuce.core.RedisClient;
import io.lettuce.core.RedisURI;
import io.lettuce.core.api.StatefulRedisConnection;
import io.lettuce.core.api.reactive.RedisStringReactiveCommands;

public class ReactiveAPI {
    public static void main(String[] args) {

        // 1. 构建 Redis 连接信息（明确指定主机、端口、密码）
        RedisURI redisURI = RedisURI.builder()
                .withHost("192.168.110.36")    // 主机地址
                .withPort(6379)                // 端口
                .withPassword("seata@user123")  // 密码（如果没有密码，可省略此句）
                .withDatabase(0)               // 数据库索引（默认0，可选）
                .build();
        // 客户端
        RedisClient client = RedisClient.create(redisURI);

//        RedisClient client = RedisClient.create("redis://127.0.0.1:6379");

        // 建立连接
        StatefulRedisConnection<String, String> connection = client.connect();

        // reactive
        RedisStringReactiveCommands<String, String> reactive = connection.reactive();

        reactive.get("gupao:reactive").subscribe(System.out::println);

        try {
            Thread.sleep(1000L);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        connection.close();
        client.shutdown();
    }
}
